<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .warp {
            width: 300px;
            height: 300px;
            border: 1px solid black;
        }

        input {
            width: 30px;
            height: 30px;
        }

        span {
            display: none;
        }
    </style>
    <!-- <script src="../../day6jquery/jquery3.5.min.js">

    </script> -->
</head>

<body>
    <div class="wrap">
        <table class="warp">
            <thead>
                <tr>
                    <th>
                        <input class="first" type="checkbox">
                    </th>
                    <th>商品</th>
                    <th>价钱</th>
                </tr>
            </thead>
            <tbody id="b">
                <tr>
                    <th>
                        <input class="child" type="checkbox">
                    </th>
                    <th>苹果8</th>
                    <th>4000</th>
                </tr>
                <tr>
                    <th>
                        <input class="child" type="checkbox">
                    </th>
                    <th>苹果8</th>
                    <th>4000</th>
                </tr>
                <tr>
                    <th>
                        <input class="child" type="checkbox">
                    </th>
                    <th>苹果8</th>
                    <th>4000</th>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        let first = document.querySelector('.first');
        let child = document.querySelectorAll('.child');
        console.log(first);
        console.log(child);
        first.onclick = function () {
            // this.checked
            console.log(' this.checked: ', this.checked);//得到当前复选框的选中状态
            for (var i = 0; i < child.length; i++) {
                child[i].checked = this.checked;
            }
        }
        for (var i = 0; i < child.length; i++) {
            child[i].onclick = function () {
                let flag = true
                for (var i = 0; i < child.length; i++) {
                    if (!child[i].checked) {
                        flag = false;
                        break;//只要有一个没被选中就会退出这个循环
                    }
                }
                first.checked = flag
            }
        }

    </script>
</body>

</html>